using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Ltf.MonitorLizard.Controls.BufferedTreeView
{
	public class HiddenChildrenNode : TreeNode
	{
		public Dictionary<int, TreeNode> SwitchableNodes = new Dictionary<int, TreeNode>();
		bool isHidden = true;

		public HiddenChildrenNode(string text)
		{
			base.Text = text;
		}

		public void AddSwitchableNode(TreeNode node)
		{
			SwitchableNodes.Add(Nodes.Count+SwitchableNodes.Count,node);
		}

		public void ShowAll()
		{
				foreach (KeyValuePair<int, TreeNode> kvp in SwitchableNodes)
				{
					TreeNode node = kvp.Value;

					if (!Nodes.Contains(node))
					{
						if (Nodes.Count == 0)
							Nodes.Add(node);
						else
							Nodes.Insert(kvp.Key, node);
					}

				}
				foreach (TreeNode child in Nodes)
				{
					if (child is HiddenChildrenNode)
					{
						((HiddenChildrenNode)child).ShowAll();
					}
				} 
				isHidden = false;
		}

		public void HideAll()
		{
				foreach (KeyValuePair<int, TreeNode> kvp in SwitchableNodes)
				{
					TreeNode node = kvp.Value;

					if (Nodes.Contains(node))
					{
						Nodes.Remove(node);
					}

				}
				foreach (TreeNode child in Nodes)
				{
					if (child is HiddenChildrenNode)
					{
						((HiddenChildrenNode)child).HideAll();
					}
				}
				isHidden = true;
		}

		public bool IsHidden
		{ 
			get { return isHidden; } 
		}
	}
}
